package prototype.simple;

/**
 * Created by IntelliJ
 * Author:熊磊
 */

public class Sheep implements Cloneable {
    private String name;
    private int age;
    private String color;
    public Sheep friend; //对象在克隆时会如何处理

    public Sheep(String name, int age, String color) {
        System.out.println("原型羊："+name+"创建成功");
        this.name = name;
        this.age = age;
        this.color = color;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    @Override
    public String toString() {
        return "Sheep{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", color='" + color + '\'' +
                '}';
    }

    //默认的clone方法
    @Override
    protected Object clone() throws CloneNotSupportedException {
        Sheep sheep = null;
        sheep = (Sheep) super.clone();  // Cloneable的克隆是返回Object对象，所以需要进行强转
        return sheep;
    }
}
